NAME=pclinuxoscz-gfxboot-theme
PACKAGE=pclinuxoscz-gfxboot-theme
#VERSION := $(shell rpm -q --qf '%{version}\n' --specfile $(NAME).spec | head -1)
#RELEASE := $(shell rpm -q --qf '%{release}\n' --specfile $(NAME).spec | head -1)

# Version identifiers: These should only be changed by the release
# manager as part of making a new release
PKGNAME=$(NAME)
MAJORVER=1
MINORVER=3
PATCHVER=4
RELVER=1
CVSVER=yes

# Automatic variable updates, leave alone
VERSION=$(MAJORVER).$(MINORVER).$(PATCHVER)
ifeq "$(CVSVER)" "yes"
	CVSDATE=$(shell date +%Y%m%d)
	RELEASE=$(CVSDATE).$(RELVER)
	ARCHIVEVER=$(VERSION)-$(CVSDATE)
else
	RELEASE=$(RELVER)
	ARCHIVEVER=$(VERSION)
endif


BINDIR      := /usr/sbin/
RPM=$(HOME)/rpm

PRODUCT      = "PCLinuxOS 2007"
export PRODUCT

HELP2TXT     = $(BINDIR)/help2txt
MKBOOTMSG    = $(BINDIR)/mkbootmsg
BFLAGS       = -O -v -L ../..
INCLUDES     = $(wildcard *.inc)
TRANSLATIONS = $(addsuffix .tr,en $(notdir $(basename $(wildcard po/*.po))))
HELPBOOT     = $(addsuffix .hlp,$(addprefix boot/,$(subst .,,$(suffix $(basename $(wildcard help-boot.*.html))))))
HELPINST     := $(addsuffix .hlp,$(addprefix inst/,$(subst .,,$(suffix $(basename $(wildcard help-install.*.html))))))

HELPBOOT_ALL = $(notdir $(HELPBOOT))
HELPINST_ALL = $(notdir $(HELPINST))

DEFAULT_LANG = cs

PIC_COMMON   = timer_a.jpg
PIC_INSTALL  = back.jpg welcome.jpg pclinuxos.pcx star.dat
PIC_BOOT     = back-low.jpg

FILES_INST   = init languages $(TRANSLATIONS) 16x16.fnt star.dat \
	       $(PIC_COMMON) $(PIC_INSTALL) $(HELPINST_ALL) isolinux.cfg

FILES_BOOT   = init languages $(TRANSLATIONS) 16x16.fnt \
	       $(PIC_COMMON) $(PIC_BOOT) $(HELPBOOT_ALL) isolinux.cfg

FILES_BOOT_EN = init languages en.tr 16x16.fnt $(PIC_COMMON) back.jpg en.hlp

INST_EXT     = 16x16.fnt $(PIC_COMMON) $(PIC_INSTALL) *.hlp *.tr lang isolinux.cfg
BOOT_EXT     = 16x16.fnt $(PIC_COMMON) back.jpg *.hlp *.tr lang isolinux.cfg

ifdef DEFAULT_LANG
FILES_INST += lang
FILES_BOOT += lang
FILES_BOOT_EN += lang $(DEFAULT_LANG).tr $(DEFAULT_LANG).hlp
endif

FILES = 16x16.fnt $(PIC_COMMON) $(PIC_INSTALL) $(PIC_BOOT) $(INCLUDES) help*.html Makefile po $(NAME).spec install.config boot.config panel.default gimp/gimprc gimp/scripts/gimp-normalize-to-bootsplash.scm languages lang isolinux.cfg

sharedir=$(prefix)/usr/share
themedir=$(sharedir)/gfxboot/themes/pclinuxoscz

boot/%.hlp: help-boot.%.html boot
	$(HELP2TXT) --product=$(PRODUCT) $< >$@

inst/%.hlp: help-install.%.html inst
	$(HELP2TXT) --product=$(PRODUCT) $< >$@

.PHONY: all themes font aafont bitmapfont clean po

all: themes

boot.config:
	$(error run 'make prep' first)

boot inst: po
	mkdir -p $@

po:
	make -C po

themes: bootdir installdir normalize

normalize:
	for i in welcome.jpg back.jpg; do \
	  echo Normalizing image $$i; \
	  if [ -f $$i ]; then \
	    echo GIMP2_DIRECTORY=`pwd`/gimp gimp --console-messages -i -d -b "(gimp-normalize-to-bootsplash 0.9 \"$$i\" )" -b "(gimp-quit 1)" ; \
	    GIMP2_DIRECTORY=`pwd`/gimp gimp --console-messages -i -d -b "(gimp-normalize-to-bootsplash 0.9 \"$$i\" )" -b "(gimp-quit 1)" ; \
	  fi \
	done

bootdir: boot.config po boot $(INCLUDES) $(HELPBOOT)
	@cp -a po/*.tr boot
	@for i in $(FILES_BOOT) ; do [ -f $$i ] && cp $$i boot ; done ; true
	@echo en >boot/languages
	$(MKBOOTMSG) $(BFLAGS) -l boot/log -c $< boot/init
ifdef DEFAULT_LANG
	@echo $(DEFAULT_LANG) >boot/lang
	@echo $(DEFAULT_LANG) >>boot/languages
endif
	@mv boot/back-low.jpg boot/back.jpg
	@sh -c 'cd boot; echo $(FILES_BOOT_EN) | sed -e "s/ /\n/g" | cpio --quiet -o >message'

installdir: install.config po inst $(INCLUDES) $(HELPINST)
	@cp -a po/*.tr inst
	@for i in $(FILES_INST) ; do [ -f $$i ] && cp $$i inst ; done ; true
	$(MKBOOTMSG) $(BFLAGS) -l inst/log -c $< inst/init
ifdef DEFAULT_LANG
	@echo $(DEFAULT_LANG) >inst/lang
endif
	@sh -c 'cd inst; chmod +t $(INST_EXT)'
	@sh -c 'cd inst; echo $(FILES_INST) | sed -e "s/ /\n/g" | cpio --quiet -o >bootlogo'
	@sh -c 'cd inst; echo init languages | sed -e "s/ /\n/g" | cpio --quiet -o >bootlogo.isolinux'

install:
	mkdir -p $(themedir)/{boot,install}
	sh -c 'cd boot; install -m644 $(BOOT_EXT) $(themedir)/boot/'
	sh -c 'cd boot; install -m644 message $(themedir)/boot/message'
	sh -c 'cd inst; install -m644 $(INST_EXT) $(themedir)/install/'
	sh -c 'cd inst; install -m644 bootlogo.isolinux $(themedir)/install/bootlogo'

font: aafont

aafont:
	cat po/*.po *.html >tmp.txt
	mkblfont -v -l 18 \
	-c ISO-8859-15 -c ISO-8859-2 -c koi8-r \
	`keymapchars keymap.*.inc` \
	-t tmp.txt \
	-t inst/log -t boot/log \
	-t languages \
	-f NachlieliCLM-Bold:size=14:c=0x590-0x5ff \
	-f KacstOne:size=18:c=0x600-0x6ff,0xfe70-0xfefc:dy=6 \
	-f MuktiNarrow:size=18:c=0x0981-0x09fa:bold=1 \
	-f lohit_hi:size=18:c=0x0901-0x0970:bold=1 \
	-f lohit_pa:size=19:c=0x0a01-0x0a74:bold=1 \
	-f KhmerOSsys:size=16:c=0x1780-0x17f9:dy=-2 \
	-f DejaVuSans-Bold:size=14 \
	-f FZHeiTi:size=17:nobitmap=1 \
	-f gulim:size=17:bold=1:nobitmap=1 \
	16x16.fnt >16x16.fnt.log
	rm -f tmp.txt

bitmapfont:
	cat po/*.po *.html >tmp.txt
	mkblfont -v -l 18 \
	-c ISO-8859-15 -c ISO-8859-2 -c koi8-r \
	`keymapchars keymap.*.inc` \
	-t tmp.txt \
	-t inst/log -t boot/log \
	-t languages \
	-f b16_b:prop=2:space_width=6 \
	16x16.fnt >16x16.fnt.log
	rm -f tmp.txt

clean:
	[ ! -f po/Makefile ] || make -C po clean
	rm -f `find -type l`
	rmdir po 2>/dev/null || true
	rm -f *~ *.log
	rm -rf boot inst $(NAME).tar.bz2 $(NAME)-$(VERSION)

prep:
	[ -e boot.config ] || { mkdir po ; ../../bin/adddir ../pclinuxos . ; }
	[ ! -f po/Makefile ] || make -C po clean
	rm -f boot install *~ *.log
	rm -rf boot inst

changelog: ../../common/username.xml
	svn2cl --accum --strip-prefix=soft/drakx/trunk --authors ../../common/username.xml
	svn -m '' commit ChangeLog

dist: localdist

cleandist:
	rm -rf $(PACKAGE)-$(VERSION) $(PACKAGE)-$(ARCHIVEVER).tar.bz2
	rm -rf $(PKGNAME).spec

dir:
	mkdir $(PACKAGE)-$(VERSION)

tar: clean dir localcopy
	tar cjvf $(PACKAGE)-$(ARCHIVEVER).tar.bz2 $(PACKAGE)-$(VERSION)
	rm -rf $(PACKAGE)-$(VERSION)

localdist:  cleandist dir localcopy tar

localcopy: dir
	tar c --exclude=.svn $(FILES) | tar x -C $(PACKAGE)-$(VERSION)

localrpm: tar $(RPM)
	cp -f $(NAME).tar $(RPM)/SOURCES
	-rpm -ba --clean $(NAME).spec
	rm -f $(NAME).tar

submit: clean ci
	mdvsys submit $(NAME)

ci: tar
	svn ci -m 'Update soft SPEC for version $(VERSION)' $(NAME).spec
	mkdir svn; cd svn; mdvsys co $(NAME)
	cp $(NAME).spec svn/$(NAME)/SPECS/
	cp $(NAME).tar svn/$(NAME)/SOURCES/
	cd svn/$(NAME)/; mdvsys ci -m 'update tarball and spec for version $(VERSION)' 

#rpm: clean ci
#	cd svn/$(NAME); bm

spec:
	cat $(PKGNAME).spec.in | \
		sed -e 's,@VERSION@,$(VERSION),g' | \
		sed -e 's,@RELEASE@,$(RELEASE),g' | \
		sed -e 's,@ARCHIVEVER@,$(ARCHIVEVER),g' \
			>$(PKGNAME).spec
	cat CHANGELOG >>$(PKGNAME).spec


	
rpm: spec tar
	rpmbuild -ta $(PACKAGE)-$(ARCHIVEVER).tar.bz2

rpm-install: rpm
	rpm -Uvh --force /usr/src/rpm/RPMS/i586/$(PKGNAME)-$(VERSION)-$(RELEASE)pclos2007.i586.rpm

gupload:
	gupload /usr/src/rpm/RPMS/i586/$(PKGNAME)-$(VERSION)-$(RELEASE)pclos2007.i586.rpm "PCLinuxOS CZ Boot Theme - binary package"

upload:
	scp /usr/src/rpm/RPMS/i586/$(PKGNAME)-$(VERSION)-$(RELEASE)pclos2007.i586.rpm dsmid@oko.clever.cz:www/pclinuxos/2007/RPMS.czech
	scp /usr/src/rpm/SRPMS/$(PKGNAME)-$(VERSION)-$(RELEASE)pclos2007.src.rpm dsmid@oko.clever.cz:www/pclinuxos/2007/SRPMS.czech
	ssh dsmid@oko.clever.cz www/pclinuxos/2007/regenerate
